﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApPSSessionData
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.Linq;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public static class CApPSSessionData
{
  private static CApSearchScopes _searchScopes;
  private static bool? _canProductStructuresBeSelected;
  private static CApStructuresAvailability? _structuresAvailability;
  private static bool isLineSimulationMode;

  public static bool CanProductStructuresBeSelected
  {
    get
    {
      if (!CApPSSessionData._canProductStructuresBeSelected.HasValue)
        CApPSSessionData._canProductStructuresBeSelected = !TxApplication.ActiveDocument.SimulationPlayer.IsLineSimulation ? (CApPSSessionData.SearchScopes.ProductScopes.Count<CUiSearchScope>() == 0 ? new bool?(false) : new bool?(true)) : new bool?(false);
      return CApPSSessionData._canProductStructuresBeSelected.Value;
    }
  }

  public static CApStructuresAvailability GetStructuresAvailability
  {
    get
    {
      bool flag = TxEngineeringDataInternal.GlobalGetPartsMode() == 2;
      if (!CApPSSessionData._structuresAvailability.HasValue || flag != CApPSSessionData.isLineSimulationMode)
      {
        CApPSSessionData._structuresAvailability = new CApStructuresAvailability?(CApStructuresAvailability.None);
        int count1 = TxTcSessionInfoEx.ProductScopes.Count;
        int count2 = TxTcSessionInfoEx.PlantScopes.Count;
        CApPSSessionData.isLineSimulationMode = flag;
        if (count1 != 0 || count2 != 0)
        {
          if (CApPSSessionData.isLineSimulationMode)
          {
            if (count2 != 0)
              CApPSSessionData._structuresAvailability = new CApStructuresAvailability?(CApStructuresAvailability.Plant);
          }
          else
            CApPSSessionData._structuresAvailability = count1 == 0 || count2 == 0 ? (count1 == 0 ? new CApStructuresAvailability?(CApStructuresAvailability.Plant) : new CApStructuresAvailability?(CApStructuresAvailability.Product)) : new CApStructuresAvailability?(CApStructuresAvailability.Both);
        }
      }
      return CApPSSessionData._structuresAvailability.Value;
    }
  }

  public static CApSearchScopes SearchScopes
  {
    get
    {
      bool flag = false;
      if (CApPSSessionData._searchScopes == null)
        flag = true;
      else if (CApPSSessionData._searchScopes.ProductScopes.Count<CUiSearchScope>() != TxTcSessionInfoEx.ProductScopes.Count || CApPSSessionData._searchScopes.PlantScopes.Count<CUiSearchScope>() != TxTcSessionInfoEx.PlantScopes.Count)
        flag = true;
      if (flag)
        CApPSSessionData._searchScopes = CApAssignDataFromTCApp.GetSearchScopes();
      return CApPSSessionData._searchScopes;
    }
  }

  public static void Clear()
  {
    CApPSSessionData._searchScopes = (CApSearchScopes) null;
    CApPSSessionData._canProductStructuresBeSelected = new bool?();
    CApPSSessionData._structuresAvailability = new CApStructuresAvailability?();
  }

  static CApPSSessionData()
  {
    TxApplication.ActiveDocument.Unloading += new TxDocument_UnloadingEventHandler(CApPSSessionData.ActiveDocument_Unloading);
  }

  private static void ActiveDocument_Unloading(object sender, TxDocument_UnloadingEventArgs args)
  {
    CApPSSessionData.Clear();
  }
}
